<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Socket接口测试</title>
</head>

<body>
    <script src="./js/jquery.min.js"></script>
    <script src="./js/socket.io.js"></script>
    <script type="text/javascript">
        $(function() {
            var myAction = {},
                socket;

            var socketConfig = {
                token: 'Bearer ' + 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ',
                task_id: '1250659e-aba9-11e8-91a6'
            };

            $.extend(myAction, {
                initSocket: function() {
                    socket = io("ws://127.0.0.1:7001", {
                        query: "token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoxLCJleHBpcmVUaW1lIjoxNjIzNTM4ODA0LCJpYXQiOjE2MjM1MzE2MDV9.ezAxvNPmQxqgswYchfk8XSkqCMUsxs2eABDBxT01SsI"
                    }); //ip
                },
                getData: function() {
                    if (socket.connected) {
                        socket.emit("greet", {
                            token: socketConfig.token
                        });
                        socket.on("greet", function(res) {
                            console.log(res);
                        });

                        socket.emit("greet", {
                            token: socketConfig.token,
                            task_id: socketConfig.task_id,
                            direction: 'down', //up, down 向上查，向下查
                            log_time: null, //日志里的时间, 1532249295
                            start_time: null, //滑动条的起始时间
                            end_time: null, //滑动条的结束时间
                            size: 10 //条数
                        });
                        socket.on("greetResult", function(res) {
                            console.log(res);
                        });

                        //下一页日志
                        socket.emit("greet", {
                            token: socketConfig.token,
                            task_id: socketConfig.task_id,
                            direction: 'down',
                            log_time: 1535560351.844,
                            start_time: null,
                            end_time: null,
                            size: 10
                        });

                        //上一页日志
                        socket.emit("greet", {
                            token: socketConfig.token,
                            task_id: socketConfig.task_id,
                            direction: 'up',
                            log_time: 1535560351.844,
                            start_time: 1535560332.681,
                            end_time: 1535560351.844,
                            size: 10
                        });

                        //下一页日志，限制结束时间
                        socket.emit("greet", {
                            token: socketConfig.token,
                            task_id: socketConfig.task_id,
                            direction: 'down',
                            log_time: 1535560351.844,
                            start_time: 1535560351.844,
                            end_time: 1535560353.463,
                            size: 10
                        });
                    } else {
                        setTimeout(myAction.getData, 500);
                    }
                },
            });

            var init = function() {
                myAction.initSocket();
                myAction.getData();
            }();
        })
    </script>
</body>

</html>